/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Multicast service core functionality header file.
 * \author Antti Maula <antti.maula@tkk.fi>
 */
#ifndef GIMNETAP_MULTICASTCORE_H_
#define GIMNETAP_MULTICASTCORE_H_

#include "protocol/fastProtocolHdr.h"
#include "protocolDispatcher.h"
#include "protocol/hubctrlHdr.h"
#include "apmulticastframe.h"
#include "multicasttable.h"

#include <inttypes.h>


void multicastcoreInit(int maxIds, int maxSubs); 
void multicastcoreDeinit(void); 



/////////// Utility functions /////////////////////////////////////////////////

int multicastcorePingNode(TProtocolDisp *link,
                          const uint32_t node_id);

int multicastcorePingNodeTable(TProtocolDisp *link,
                               TMulticastTableEntry *entry,
                               float check_probability);


int multicastcoreRegisterMulticastId(const uint32_t mcast_id, 
                                     const uint64_t mcast_owner_key, 
                                     const uint64_t mcast_access_key,
                                     const EMulticastType type);

int multicastcoreUnsubscribeNodeId(TMulticastTableEntry *entry,
                                   const uint32_t node_id);

int multicastcoreUnsubscribeNodeIdFromAll(const uint32_t node_id);


/////////// Request handlers //////////////////////////////////////////////////

int multicastcoreRequestCreateMulticastId(TAPMulticastFrame *replyframe,
                                          TAPMulticastCtrl *replyctrl,
                                          const TAPMulticastFrame *mcframe,
                                          const TAPMulticastCtrl *mcctrl,
                                          const TFastProtocolHeader *fphdr);

int multicastcoreRequestPublishPublic(TAPMulticastFrame *replyframe,
                                      TAPMulticastCtrl *replyctrl,
                                      const TAPMulticastFrame *mcframe,
                                      const TAPMulticastCtrl *mcctrl,
                                      const TFastProtocolHeader *fphdr);

int multicastcoreRequestSubscribe(TAPMulticastFrame *replyframe,
                                  TAPMulticastCtrl *replyctrl,
                                  const TAPMulticastFrame *mcframe,
                                  const TAPMulticastCtrl *mcctrl,
                                  const TFastProtocolHeader *fphdr);

int multicastcoreRequestUnsubscribe(TAPMulticastFrame *replyframe,
                                    TAPMulticastCtrl *replyctrl,
                                    const TAPMulticastFrame *mcframe,
                                    const TAPMulticastCtrl *mcctrl,
                                    const TFastProtocolHeader *fphdr);

int multicastcoreRequestMulticast(TAPMulticastFrame *replyframe,
                                  TAPMulticastCtrl *replyctrl,
                                  TProtocolDisp *link,
                                  const TAPMulticastFrame *mcframe, 
                                  const TAPMulticastCtrl *mcctrl,
                                  const TAPMulticastPayload *mcpayload, 
                                  const TFastProtocolHeader *framehdr);

#endif
